/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include <iostream>
#include "gtest/gtest.h"
// #include "mockcpp/mockcpp.hpp"
#include "stub.h"
#include "ApplicationProtectPlugin_types.h"
#include "ApplicationProtectBaseDataType_types.h"
#include "BuildIndexServiceJob.h"
#include "ClientInvoke.h"
#include "PluginUtilities.h"

using namespace AppProtect;
using namespace std;

class Scanner_test_Index : public Scanner {
public:
    explicit Scanner_test_Index(const ScanConfig& scanConfig);
    ~Scanner_test_Index() {};

    SCANNER_STATUS Start() override;
    SCANNER_STATUS Abort()override;
    SCANNER_STATUS Destroy() override;
    SCANNER_STATUS Enqueue(const std::string& directory, const std::string& prefix = "", uint8_t filterFlag = 0) override;
    SCANNER_STATUS EnqueueV2(const std::string& directory) override;
    SCANNER_STATUS GetStatus() override;
    ScanStatistics GetStatistics() override;
    ErrRecorder QueryFailure() override;

protected:
    ScanConfig m_config;
};

Scanner_test_Index::Scanner_test_Index(const ScanConfig& scanConfig) : Scanner(scanConfig) {}
SCANNER_STATUS Scanner_test_Index::Start() {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS Scanner_test_Index::Abort() {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS Scanner_test_Index::Destroy() {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS Scanner_test_Index::Enqueue(const std::string& directory, const std::string& prefix, uint8_t filterFlag) {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS Scanner_test_Index::EnqueueV2(const std::string& directory) {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS Scanner_test_Index::GetStatus() {
    return SCANNER_STATUS::COMPLETED;
}
ScanStatistics Scanner_test_Index::GetStatistics() {
    ScanStatistics scanStatistics;
    return scanStatistics;
}

ErrRecorder Scanner_test_Index::QueryFailure() {
    ErrRecorder errRecorder {};
    return errRecorder;
}

class BuildIndexServiceJobTest : public testing::Test {
public:
    void SetUp();
    void TearDown();
    static void SetUpTestCase() {}
    static void TearDownTestCase() {}
    void SetStubScanMgrInstance();
    void ResetStubScanMgrInstance();
    Stub stub;
    // AppProtect::BuildIndexJob BuildIndexJobSetup();
    std::unique_ptr<BuildIndexServiceJob> m_nasBuildIndexServiceJob;
};

static void ReportJobDetailsSuc(void *obj, ActionResult& returnValue, const SubJobDetails& jobInfo)
{
    return;
}

static void AddNewJobSuc(void *obj, ActionResult& returnValue, const std::vector<SubJob>& job)
{
    return;
}

static AppProtect::BuildIndexJob BuildIndexJobSetup(bool preTag, string subType)
{
    vector<string> paths {};
    paths.push_back("/");

    BuildIndexJob buildIndexJob;
    buildIndexJob.__set_jobId("buildIndexJobTest");
    
    HostAddress remoteHost;
    remoteHost.__set_ip("192.168.97.233");
    remoteHost.__set_port(0);
    vector<HostAddress> remoteHostList { remoteHost };

    Copy copy1 {};
    vector<StorageRepository> repos1 {};
    
    StorageRepository preRepo;
    preRepo.__set_extendInfo("{\"copyId\":\"precopyId\", \"isCurrentCopyRepo\": false, \"timestamp\": 1644374672}");
    preRepo.__set_protocol(RepositoryProtocolType::type::NFS);
    preRepo.__set_remoteHost(remoteHostList);
    preRepo.__set_remotePath("/clone_Storage_e8325923-8f2b-39d1-82be-5f95e7e94d85_ac0bfb65-aab8-4429-bf75-b45c99aa35b6_build_index");
    preRepo.__set_repositoryType(RepositoryDataType::type::DATA_REPOSITORY);
    
    StorageRepository cacheRepo;
    cacheRepo.__set_protocol(RepositoryProtocolType::type::NFS);
    cacheRepo.__set_remoteHost(remoteHostList);
    cacheRepo.__set_path(paths);
    cacheRepo.__set_remotePath("/Storage_CacheDataRepository/e8325923-8f2b-39d1-82be-5f95e7e94d85");
    cacheRepo.__set_repositoryType(RepositoryDataType::type::CACHE_REPOSITORY);

    StorageRepository curRepo;
    curRepo.__set_extendInfo("{\"copyId\":\"curcopyId\", \"isCurrentCopyRepo\": true, \"timestamp\": 1644375986}");
    curRepo.__set_protocol(RepositoryProtocolType::type::NFS);
    curRepo.__set_remoteHost(remoteHostList);
    curRepo.__set_remotePath("/clone_Storage_e8325923-8f2b-39d1-82be-5f95e7e94d85_19dfe194-c7e6-4272-9398-17cb712ee428_build_index");
    curRepo.__set_repositoryType(RepositoryDataType::type::DATA_REPOSITORY);

    StorageRepository indexRepo;
    // indexRepo.__set_extendInfo("{\"copyId\":\"curcopyId\", \"isCurrentCopyRepo\": true, \"timestamp\": 1644375986}");
    indexRepo.__set_protocol(RepositoryProtocolType::type::NFS);
    indexRepo.__set_remoteHost(remoteHostList);

    indexRepo.__set_path(paths);
    indexRepo.__set_remotePath("/clone_Storage_e8325923-8f2b-39d1-82be-5f95e7e94d85_19dfe194-c7e6-4272-9398-17cb712ee428_build_index");
    indexRepo.__set_repositoryType(RepositoryDataType::type::INDEX_REPOSITORY);

    StorageRepository metaRepo;
    metaRepo.__set_extendInfo(R"({"copyId":"curcopyId", "isCurrentCopyRepo": true, "timestamp": 123})");
    metaRepo.__set_protocol(RepositoryProtocolType::type::NFS);
    metaRepo.__set_remoteHost(remoteHostList);
    metaRepo.__set_path(paths);
    metaRepo.__set_remotePath("/");
    metaRepo.__set_repositoryType(RepositoryDataType::type::META_REPOSITORY);

    StorageRepository preMetaRepo;
    preMetaRepo.__set_extendInfo(R"({"copyId":"curcopyId", "isCurrentCopyRepo": false, "timestamp": 456})");
    preMetaRepo.__set_protocol(RepositoryProtocolType::type::NFS);
    preMetaRepo.__set_remoteHost(remoteHostList);
    preMetaRepo.__set_path(paths);
    preMetaRepo.__set_remotePath("/");
    preMetaRepo.__set_repositoryType(RepositoryDataType::type::META_REPOSITORY);

    repos1.push_back(cacheRepo);
    repos1.push_back(curRepo);
    repos1.push_back(indexRepo);
    repos1.push_back(metaRepo);

    if (preTag) {
        repos1.push_back(preMetaRepo);
        repos1.push_back(preRepo);
    }

    copy1.__set_repositories(repos1);

    BuildIndexJobParam jobParam {};
    jobParam.__set_indexPath("/home/shuai/diffPath");
    jobParam.__set_preCopyId("preCopyId");
    
    vector<Copy> copies {};
    copies.push_back(copy1);

    vector<StorageRepository> indexRepoList;
    indexRepoList.push_back(indexRepo);
    buildIndexJob.indexProtectObject.subType = subType;
    // buildIndexJob.indexProtectObject.subType = "NasFileSystem";
    buildIndexJob.__set_repositories(indexRepoList);
    buildIndexJob.__set_jobParam(jobParam);
    buildIndexJob.__set_copies(copies);

    return buildIndexJob;
}

shared_ptr<JobCommonInfo> GetJobInfo_Stub_correct_val(void* obj)
{
    cout << "Call GetJobInfo_Stub_correct_val" << endl;
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(true, "NasFileSystem");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    return jobInfo;
}

static unique_ptr<Scanner> CreateScanInst_Stub (void* obj, ScanConfig& scanConfig) {
    ScanConfig xx;
    return make_unique<Scanner_test_Index>(xx);
}

static void returnVoidStub(void* obj)
{
    return;
}

class ScanTest : public Scanner {
public:
    explicit ScanTest(const ScanConfig& scanConfig);
    ~ScanTest() override;

    SCANNER_STATUS Start() override;
    SCANNER_STATUS Abort() override;
    SCANNER_STATUS Destroy() override;
    SCANNER_STATUS Enqueue(const std::string& directory, const std::string& prefix = "", uint8_t filterFlag = 0) override;
    SCANNER_STATUS EnqueueV2(const std::string& directory) override;
    SCANNER_STATUS GetStatus() override;
    ScanStatistics GetStatistics() override;
    ErrRecorder QueryFailure() override;
};

ScanTest::ScanTest(const ScanConfig& scanConfig) : Scanner(scanConfig) {};

ScanTest::~ScanTest() {};

SCANNER_STATUS ScanTest::Start() {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS ScanTest::Abort() {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS ScanTest::Destroy() {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS ScanTest::Enqueue(const std::string& directory, const std::string& prefix, uint8_t filterFlag) {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS ScanTest::EnqueueV2(const std::string& directory) {
    return SCANNER_STATUS::SUCCESS;
}
SCANNER_STATUS ScanTest::GetStatus() {
    return SCANNER_STATUS::COMPLETED;
}
ScanStatistics ScanTest::GetStatistics() {
    ScanStatistics scanStats {};
    return scanStats;
}

ErrRecorder ScanTest::QueryFailure() {
    ErrRecorder errRecorder {};
    return errRecorder;
}
static unique_ptr<Scanner> CreateScanInstStub_Succ(void* obj, const ScanConfig& scanConfig) {
    ScanConfig emptInfo;
    unique_ptr<Scanner> scanInst = make_unique<ScanTest>(emptInfo);
    return scanInst;
}

void BuildIndexServiceJobTest::SetUp()
{
    stub.set(sleep, returnVoidStub);
    m_nasBuildIndexServiceJob = std::make_unique<BuildIndexServiceJob>();
    // MOCKER_CPP(&BasicJob::GetJobInfo).stubs().will(invoke(GetJobInfo_Stub_correct_val));
    // stub.set(ADDR(BasicJob, GetJobInfo), GetJobInfo_Stub_correct_val);

    SubJob subJob;
    // subJobId keyword is optional, this operation is necessary
    subJob.__isset.subJobId = true;
    subJob.__set_jobId("sub_job_id");
    subJob.jobId = "jobId123";
    subJob.subJobId = "subJob123";
    subJob.jobName = "XYZ";
    subJob.jobPriority = 1;
    subJob.jobInfo = "{\"ControlFile\":\"\",\"SubTaskType\":1,\"Ext\":\"\"}";

    std::shared_ptr<SubJob> subJobptr = std::make_shared<SubJob>(subJob);
    m_nasBuildIndexServiceJob->SetSubJob(subJobptr);
}

void BuildIndexServiceJobTest::TearDown()
{
    // GlobalMockObject::verify();
    // stub.reset(ADDR(BasicJob, GetJobInfo));
}

static void ReportJobDetails_Stub(void *ob, ActionResult& returnValue, const SubJobDetails& jobInfo)
{
    return;
}

static bool IsFileExist_Success(const std::string& fileName)
{
    return true;
}

static bool IsFileExist_Failed(const std::string& fileName)
{
    return false;
}

/*
 * 用例名称: CheckPrerequisiteJobSuc
 * 前置条件：
 * check点：前置任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckPrerequisiteJobSuc)
{
    EXPECT_EQ(m_nasBuildIndexServiceJob->PrerequisiteJob(), 0);
}

/*
 * 用例名称: CheckPostJobSuc
 * 前置条件：
 * check点：后置任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckPostJobSuc)
{
    EXPECT_EQ(m_nasBuildIndexServiceJob->PostJob(), 0);
}

/*
 * 用例名称: CheckCheckBackupJobTypeSuc
 * 前置条件：
 * check点：CheckBackupJobType成功
 */
TEST_F(BuildIndexServiceJobTest, CheckCheckBackupJobTypeSuc)
{
    EXPECT_EQ(m_nasBuildIndexServiceJob->CheckBackupJobType(), 0);
}

/*
 * 用例名称: CheckPrerequisiteJobInnerSuc
 * 前置条件：
 * check点：前置任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckPrerequisiteJobInnerSuc)
{
    EXPECT_EQ(m_nasBuildIndexServiceJob->PrerequisiteJobInner(), 0);
}

/*
 * 用例名称: CheckFillMonitorScannerVarDetails
 * 前置条件：
 * check点：根据m_scanStatus不同状态返回对应值
 */
TEST_F(BuildIndexServiceJobTest, CheckFillMonitorScannerVarDetails)
{
    auto obj_index = std::make_unique<BuildIndexServiceJob>();
    BuildIndexServiceJob::SCANNER_TASK_STATUS scanTaskStatus = 
        BuildIndexServiceJob::SCANNER_TASK_STATUS::SCANNER_TASK_STATUS_SUCCESS;
    SubJobStatus::type jobStatus = SubJobStatus::COMPLETED;
    obj_index->m_scanStatus = SCANNER_STATUS::FAILED;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus);
    EXPECT_EQ(jobStatus, SubJobStatus::FAILED);

    obj_index->m_scanStatus = SCANNER_STATUS::ABORT_IN_PROGRESS;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus);
    EXPECT_EQ(jobStatus, SubJobStatus::ABORTING);

    obj_index->m_scanStatus = SCANNER_STATUS::ABORTED;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus);
    EXPECT_EQ(jobStatus, SubJobStatus::ABORTED);

    obj_index->m_scanStatus = SCANNER_STATUS::SCAN_READ_COMPLETED;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus);
    EXPECT_EQ(jobStatus, SubJobStatus::RUNNING);

    obj_index->m_scanStatus = SCANNER_STATUS::CTRL_DIFF_IN_PROGRESS;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus);
    EXPECT_EQ(jobStatus, SubJobStatus::RUNNING);

    obj_index->m_scanStatus = SCANNER_STATUS::SECONDARY_SERVER_NOT_REACHABLE;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus);
    EXPECT_EQ(jobStatus, SubJobStatus::FAILED);

    obj_index->m_scanStatus = SCANNER_STATUS::PROTECTED_SERVER_NOT_REACHABLE;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus);
    EXPECT_EQ(jobStatus, SubJobStatus::FAILED);

    obj_index->m_scanStatus = SCANNER_STATUS::ERROR_INC_TO_FULL;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus);
    EXPECT_EQ(jobStatus, SubJobStatus::FAILED);
}

/*
 * 用例名称: CheckGenerateSubJob
 * 前置条件：
 * check点：生成子任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckGenerateSubJob)
{
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(true, "NasFileSystem");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    m_nasBuildIndexServiceJob->m_jobCommonInfo = jobInfo;
    EXPECT_EQ(m_nasBuildIndexServiceJob->GenerateSubJob(), 0);
}

static bool Initiate_Stub (void* obj, ScanConfig& scanConfig) {
    return true;
}

static SCANNER_STATUS StartScan_Stub(void* obj) {
    return SCANNER_STATUS::SUCCESS;
}

static SCANNER_STATUS AbortScan_Stub(void* obj) {
    return SCANNER_STATUS::SUCCESS;
}

static void Destroy_Stub(void* obj) {
    return;
}

static void Enqueue_Stub(void* obj, std::string directory, std::string prefix, uint8_t filterFlag) {
    return;
}

static SCANNER_STATUS GetScanStatus_Stub(void* obj) {
    return SCANNER_STATUS::COMPLETED;
}

static ScanStatistics GetScanStats_Stub(void* obj) {
    ScanStatistics scanStatistics;
    return scanStatistics;
}

void BuildIndexServiceJobTest::SetStubScanMgrInstance()
{
    stub.set(ADDR(ScanMgr, Initiate), Initiate_Stub);
    stub.set(ADDR(ScanMgr, StartScan), StartScan_Stub);
    stub.set(ADDR(ScanMgr, AbortScan), AbortScan_Stub);
    stub.set(ADDR(ScanMgr, Destroy), Destroy_Stub);
    stub.set(ADDR(ScanMgr, Enqueue), Enqueue_Stub);
    stub.set(ADDR(ScanMgr, GetScanStatus), GetScanStatus_Stub);
    stub.set(ADDR(ScanMgr, GetScanStats), GetScanStats_Stub);
    stub.set(ADDR(ScanMgr, CreateScanInst), CreateScanInstStub_Succ);
}

void BuildIndexServiceJobTest::ResetStubScanMgrInstance()
{
    stub.reset(ADDR(ScanMgr, Initiate));
    stub.reset(ADDR(ScanMgr, StartScan));
    stub.reset(ADDR(ScanMgr, AbortScan));
    stub.reset(ADDR(ScanMgr, Destroy));
    stub.reset(ADDR(ScanMgr, Enqueue));
    stub.reset(ADDR(ScanMgr, GetScanStatus));
    stub.reset(ADDR(ScanMgr, GetScanStats));
    stub.reset(ADDR(ScanMgr, CreateScanInst));
}

static int RunShell_Success(const severity_level& severity, const string& moduleName,
        const size_t& requestID, const string& cmd, const vector<string> params,
        vector<string>& cmdoutput, vector<string>& stderroutput)
{
    return 0;
}

static int Return_ProcessHomoScan(bool isCur)
{
    return -1;
}

//以下几个ExecuteSubJob用例根据参数不同，覆盖不同分支
/*
 * 用例名称: CheckExecuteSubJobFileInc
 * 前置条件：
 * check点：执行子任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckExecuteSubJobFileInc)
{
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(true, "NasFileSystem");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    m_nasBuildIndexServiceJob->m_jobCommonInfo = jobInfo;
    SetStubScanMgrInstance();
    stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
    stub.set(PluginUtils::IsFileExist, IsFileExist_Success);
    stub.set(Module::runShellCmdWithOutput, RunShell_Success);
    EXPECT_EQ(m_nasBuildIndexServiceJob->ExecuteSubJob(), 0);
    ResetStubScanMgrInstance();
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(PluginUtils::IsFileExist);
    stub.reset(Module::runShellCmdWithOutput);
}

/*
 * 用例名称: CheckExecuteSubJobFileNoExist
 * 前置条件：
 * check点：执行子任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckExecuteSubJobFileNoExist)
{
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(true, "NasFileSystem");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    m_nasBuildIndexServiceJob->m_jobCommonInfo = jobInfo;
    SetStubScanMgrInstance();
    stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
    stub.set(PluginUtils::IsFileExist, IsFileExist_Failed);
    stub.set(Module::runShellCmdWithOutput, RunShell_Success);
    EXPECT_EQ(m_nasBuildIndexServiceJob->ExecuteSubJob(), 0);
    ResetStubScanMgrInstance();
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(PluginUtils::IsFileExist);
    stub.reset(Module::runShellCmdWithOutput);
}

/*
 * 用例名称: CheckExecuteSubJobFileNoExist
 * 前置条件：
 * check点：执行子任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckExecuteSubJobFileFull)
{
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(false, "NasFileSystem");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    m_nasBuildIndexServiceJob->m_jobCommonInfo = jobInfo;
    SetStubScanMgrInstance();
    stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
    stub.set(PluginUtils::IsFileExist, IsFileExist_Success);
    stub.set(Module::runShellCmdWithOutput, RunShell_Success);
    EXPECT_EQ(m_nasBuildIndexServiceJob->ExecuteSubJob(), 0);
    ResetStubScanMgrInstance();
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(PluginUtils::IsFileExist);
    stub.reset(Module::runShellCmdWithOutput);
}

/*
 * 用例名称: CheckExecuteSubJobFileNoExist
 * 前置条件：
 * check点：执行子任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckExecuteSubJobShareInc)
{
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(true, "NasShare");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    m_nasBuildIndexServiceJob->m_jobCommonInfo = jobInfo;
    SetStubScanMgrInstance();
    stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
    stub.set(PluginUtils::IsFileExist, IsFileExist_Success);
    stub.set(Module::runShellCmdWithOutput, RunShell_Success);
    EXPECT_EQ(m_nasBuildIndexServiceJob->ExecuteSubJob(), 0);
    ResetStubScanMgrInstance();
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(PluginUtils::IsFileExist);
    stub.reset(Module::runShellCmdWithOutput);
}

/*
 * 用例名称: CheckExecuteSubJobFileNoExist
 * 前置条件：
 * check点：执行子任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckExecuteSubJobShareFull)
{
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(false, "NasShare");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    m_nasBuildIndexServiceJob->m_jobCommonInfo = jobInfo;
    SetStubScanMgrInstance();
    stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
    stub.set(PluginUtils::IsFileExist, IsFileExist_Success);
    stub.set(Module::runShellCmdWithOutput, RunShell_Success);
    EXPECT_EQ(m_nasBuildIndexServiceJob->ExecuteSubJob(), 0);
    ResetStubScanMgrInstance();
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(PluginUtils::IsFileExist);
    stub.reset(Module::runShellCmdWithOutput);
}

/*
 * 用例名称: CheckScannerCtrlFileCallBack
 * 前置条件：
 * check点：ScannerCtrlFileCallBack正常调用
 */
TEST_F(BuildIndexServiceJobTest, CheckScannerCtrlFileCallBack)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    m_nasBuildIndexServiceJob->ScannerCtrlFileCallBack(usrData, controlFilePath);
    EXPECT_EQ(0, 0);
}

/*
 * 用例名称: CheckScannerHardLinkCallBack
 * 前置条件：
 * check点：ScannerHardLinkCallBack正常调用
 */
TEST_F(BuildIndexServiceJobTest, CheckScannerHardLinkCallBack)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    m_nasBuildIndexServiceJob->ScannerHardLinkCallBack(usrData, controlFilePath);
    EXPECT_EQ(0, 0);
}

/*
 * 用例名称: CheckBackupDirMTimeCallBack
 * 前置条件：
 * check点：BackupDirMTimeCallBack正常调用
 */
TEST_F(BuildIndexServiceJobTest, CheckBackupDirMTimeCallBack)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    m_nasBuildIndexServiceJob->BackupDirMTimeCallBack(usrData, controlFilePath);
    EXPECT_EQ(0, 0);
}

/*
 * 用例名称: CheckBackupDelCtrlCallBack
 * 前置条件：
 * check点：BackupDelCtrlCallBack正常调用
 */
TEST_F(BuildIndexServiceJobTest, CheckBackupDelCtrlCallBack)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    m_nasBuildIndexServiceJob->BackupDelCtrlCallBack(usrData, controlFilePath);
    EXPECT_EQ(0, 0);
}

/*
 * 用例名称: CheckExecuteSubJobFileNoExist
 * 前置条件：
 * check点：执行子任务成功
 */
TEST_F(BuildIndexServiceJobTest, CheckGeneratedCopyCtrlFileCb)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    m_nasBuildIndexServiceJob->GeneratedCopyCtrlFileCb(usrData, controlFilePath);
    EXPECT_EQ(0, 0);
}

/*
 * 用例名称: CheckGeneratedHardLinkCtrlFileCb
 * 前置条件：
 * check点：GeneratedHardLinkCtrlFileCb正常调用
 */
TEST_F(BuildIndexServiceJobTest, CheckGeneratedHardLinkCtrlFileCb)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    m_nasBuildIndexServiceJob->GeneratedHardLinkCtrlFileCb(usrData, controlFilePath);
    EXPECT_EQ(0, 0);
}

/*
 * 用例名称: CheckGenerateRfiCtrlFileCb
 * 前置条件：
 * check点：GenerateRfiCtrlFileCb正常调用
 */
TEST_F(BuildIndexServiceJobTest, CheckGenerateRfiCtrlFileCb)
{
    void *usrData = 0;
    RfiCbStruct cbParam = {"1", "1", "1", "1.txt", true, true};
    m_nasBuildIndexServiceJob->GenerateRfiCtrlFileCb(usrData, cbParam);
    EXPECT_EQ(0, 0);

    RfiCbStruct cbParam2 = {"1", "1", "1", "1.txt", true, false};
    m_nasBuildIndexServiceJob->GenerateRfiCtrlFileCb(usrData, cbParam2);
    EXPECT_EQ(0, 0);
}

/*
 * 用例名称: CheckExecuteSubJobFileNoExist
 * 前置条件：
 * check点：执行子任务失败
 */
TEST_F(BuildIndexServiceJobTest, CheckExecuteSubJobFileIncFailed)
{
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(true, "NasFileSystem");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    m_nasBuildIndexServiceJob->m_jobCommonInfo = jobInfo;
    SetStubScanMgrInstance();
    stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
    stub.set(PluginUtils::IsFileExist, IsFileExist_Success);
    stub.set(Module::runShellCmdWithOutput, RunShell_Success);
    stub.set(ADDR(BuildIndexServiceJob,ProcessHomoScan), Return_ProcessHomoScan);
    EXPECT_EQ(m_nasBuildIndexServiceJob->ExecuteSubJob(), 0);
    ResetStubScanMgrInstance();
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(PluginUtils::IsFileExist);
    stub.reset(Module::runShellCmdWithOutput);
    stub.reset(ADDR(BuildIndexServiceJob,ProcessHomoScan));
}

/*
 * 用例名称: CheckExecuteSubJobFileNoExist
 * 前置条件：
 * check点：执行子任务失败
 */
TEST_F(BuildIndexServiceJobTest, CheckExecuteSubJobFileNoExistFailed)
{
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(true, "NasFileSystem");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    m_nasBuildIndexServiceJob->m_jobCommonInfo = jobInfo;
    SetStubScanMgrInstance();
    stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
    stub.set(PluginUtils::IsFileExist, IsFileExist_Failed);
    stub.set(Module::runShellCmdWithOutput, RunShell_Success);
    stub.set(ADDR(BuildIndexServiceJob,ProcessHomoScan), Return_ProcessHomoScan);
    EXPECT_EQ(m_nasBuildIndexServiceJob->ExecuteSubJob(), -1);
    ResetStubScanMgrInstance();
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(PluginUtils::IsFileExist);
    stub.reset(Module::runShellCmdWithOutput);
    stub.reset(ADDR(BuildIndexServiceJob,ProcessHomoScan));
}

/*
 * 用例名称: CheckExecuteSubJobFileNoExist
 * 前置条件：
 * check点：执行子任务失败
 */
TEST_F(BuildIndexServiceJobTest, CheckExecuteSubJobFileFullFailed)
{
    AppProtect::BuildIndexJob indexJob = BuildIndexJobSetup(false, "NasFileSystem");
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BuildIndexJob>(indexJob));
    m_nasBuildIndexServiceJob->m_jobCommonInfo = jobInfo;
    SetStubScanMgrInstance();
    stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
    stub.set(PluginUtils::IsFileExist, IsFileExist_Success);
    stub.set(Module::runShellCmdWithOutput, RunShell_Success);
    stub.set(ADDR(BuildIndexServiceJob,ProcessHomoScan), Return_ProcessHomoScan);
    EXPECT_EQ(m_nasBuildIndexServiceJob->ExecuteSubJob(), -1);
    ResetStubScanMgrInstance();
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(PluginUtils::IsFileExist);
    stub.reset(Module::runShellCmdWithOutput);
    stub.reset(ADDR(BuildIndexServiceJob,ProcessHomoScan));
}